package com.example.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.bean.CmsComment;
import com.example.demo.bean.CmsLink;
import com.example.demo.common.Respones;
import com.example.demo.service.CmsCommentService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(tags = "评论管理服务")
@RestController
@RequestMapping("/comment")
public class CmsCommentController {
	@Autowired
	private CmsCommentService commentservice;
	
	//评论状态
		@ApiOperation(value = "审核评论")
		@ApiImplicitParams({
			@ApiImplicitParam(name="comId",value = "评论编号"),
			@ApiImplicitParam(name = "state",value = "状态",
								allowableValues = "已通过,未通过")
		})
		@PutMapping(value = "/updateState")
		public Respones<String> updateState(String comId,
				String  state){
			boolean m = commentservice.updateState(comId, state);
			if(m) return Respones.ok("操作成功！");
			else return Respones.error("要更新的会员不存在！");
		}
	
	
	//按评论编号删除评论信息
			@ApiOperation(value = "按照评论编号，删除评论信息！")
			@DeleteMapping("/deleteById")
			public Respones<String> deleteById(String id){
				int count = commentservice.deleteById(id);
				return Respones.ok("删除成功" + count+"条评论");	
			}
	
	//获取所有评论信息
			@ApiOperation(value = "获取所有评论信息",notes="从数据库检索所有评论信息")
			@GetMapping("/all")
			public Respones<List<CmsComment>> queryAll(){
				//调用业务方法
				List<CmsComment> cc=commentservice.getAllComment();
				return Respones.ok(cc);
			}
}
